<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>15-鼠标经过/离开事件的区别</title>
    <style>
      .father {
        overflow: hidden;
        width: 500px;
        height: 500px;
        background-color: pink;
        margin: 100px auto;
        text-align: center;
      }

      .son {
        width: 300px;
        height: 300px;
        background-color: skyblue;
        margin: 80px auto;
        text-align: center;
        line-height: 300px;
      }
    </style>
  </head>
  <body>
    <div class="father">
      父盒子
      <div class="son">子盒子</div>
    </div>

    <script>
      const father = document.querySelector('.father')
      const son = document.querySelector('.son')

     
      // 1.mouseover 和 mouseout 有事件冒泡
      // father.addEventListener('mouseover', function () {
      //   console.log('鼠标经过了爸爸')
      // })
      // father.addEventListener('mouseout', function () {
      //   console.log('鼠标经过了爸爸')
      // })

      // son.addEventListener('mouseover', function () {
      //   console.log('鼠标经过了儿子')
      // })
      // son.addEventListener('mouseout', function () {
      //   console.log('鼠标经过了儿子')
      // })


      // 2. mouseenter 和 mouseleave 没有冒泡效果 (推荐)
      // father.addEventListener('mouseenter', function () {
      //   console.log('鼠标经过了爸爸')
      // })
      // son.addEventListener('mouseenter', function () {
      //   console.log('鼠标经过了儿子')
      // })
      father.addEventListener('mouseleave', function () {
        console.log('鼠标经过了爸爸')
      })
      son.addEventListener('mouseleave', function () {
        console.log('鼠标经过了儿子')
      })
    </script>
  </body>
</html>
